use fluffy::{DbRow, model::Model,};
use crate::models::ModelBackend;
use crate::validations::Validator;
use std::collections::HashMap;

#[crud_table]
#[derive(Default, Clone, Debug, Serialize, Deserialize)]
pub struct Music {
    pub id: usize,
    pub name: String,
    pub delete_flag: i32,
}


impl Model for Music {
    fn get_table_name() -> &'static str { "music" }
}

impl ModelBackend for Music {

    type M = Self;

    get_fields!(Self, [
        id => usize,
        name => String,
        delete_flag => i32,
    ]);

    fn validate(data: &HashMap<String, String>) -> Result<(), String> {
        Validator::load(&data)
            .string_length("name", "音乐名称必须在2-20之间", 2, 20, true)
            .validate()
    }
}